//
//  UITableViewCell+HDGoodsCollectCell.m
//  app
//
//  Created by D on 15/7/8.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HDGoodsCollectCell.h"

static const CGFloat kCartCellMargin = 24.0f;
static const CGFloat kCartGoodsPictureHeight = 160.0f;
static const CGFloat kCartCellSelectBtnWidth = 64.0f;
static const CGFloat kCartGoodsNumBtnWidth = 120.0f;
static const CGFloat kCartGoodsNumBtnHeight = 60.0f;

static const CGFloat kCartCellPadding = 20.0f;

@implementation HDGoodsCollectCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.contentMode = UIViewContentModeRedraw;
        self.frame = CGRectOf([self.ufo fx:UB_LEFT fy:UB_TOP], [UBO_SCREEN fw:UB_WIDTH uh:kCartGoodsPictureHeight + 2*kCartCellMargin]);
        
    }
    return self;
}

-(void)cellWithModel:(HDGoodCollectModel *)model
{
    
    //初始化全选按钮
    self.selectBtn = [[UIButton alloc] initWithFrame:CGRectOf([self.ubo fx:UB_LEFT fy:UB_TOP],
                                                              [self.ubo uw:kCartCellSelectBtnWidth fh:UB_HEIGHT])];
    [self.selectBtn setImage:[UIImage imageNamed:kImageMallCartGoodUnselect] forState:UIControlStateNormal];
    [self.selectBtn setImage:[UIImage imageNamed:kImageMallCartGoodSelected] forState:UIControlStateSelected];
    self.selectBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    self.selectBtn.backgroundColor = HZ_CLEAR_COLOR;
    [self.selectBtn addTarget:self action:@selector(selectBtnOnClick) forControlEvents:UIControlEventTouchUpInside];
//    [self addSubview:self.selectBtn];
    
    
    //初始化图片按钮
    self.goodsPic = [[UIImageView alloc] initWithFrame:CGRectOf([self.ubo fx:UB_LEFT ux:kCartCellMargin*2 fy:UB_TOP uy:kCartCellMargin],
                                                                [self.ubo uw:kCartGoodsPictureHeight uh:kCartGoodsPictureHeight])];
    self.goodsPic.backgroundColor = HZ_MALL_M_LIGHT_GRAY_BACKGROUND_COLOR;
    self.goodsPic.layer.masksToBounds = YES;
    self.goodsPic.layer.cornerRadius = [self.ubo uw:4];
    self.goodsPic.layer.borderColor = HZ_MALL_M_LIGHT_GRAY_BACKGROUND_COLOR.CGColor;
    self.goodsPic.layer.borderWidth = [self.ubo pw:2];
    [self.goodsPic sd_setImageWithURL:[NSURL URLWithString:model.title_pic]];
    [self addSubview:self.goodsPic];
    
    //初始化商品标题
    CGFloat goodsTitleWidth = [self.ubo fw:UB_WIDTH uw:-(kCartCellMargin + 2*kCartCellPadding + kCartGoodsPictureHeight +kCartCellSelectBtnWidth)];
    self.goodsTitleLabel = [[UILabel alloc] initWithFrame:CGRectOf([self.goodsPic.ufo fx:UB_RIGHT ux:kCartCellPadding fy:UB_TOP],
                                                                   [self.goodsPic.ubo ow:goodsTitleWidth fh:UB_HALF])];
    self.goodsTitleLabel.backgroundColor = HZ_CLEAR_COLOR;
    [self.goodsTitleLabel setTextColor:HZ_MALL_TEXT_BLACK_COLOR];
    self.goodsTitleLabel.textAlignment = NSTextAlignmentLeft;
    [self.goodsTitleLabel setFont:JKAppGlobleFontMenu];
    self.goodsTitleLabel.numberOfLines = 0;
    self.goodsTitleLabel.textAlignment = NSTextAlignmentLeft;
    self.goodsTitleLabel.text = model.title;
    [self addSubview:self.goodsTitleLabel];
    
    //初始化价格标签
    self.goodsPriceLabel = [[UILabel alloc] initWithFrame:CGRectOf([self.goodsPic.ufo fx:UB_RIGHT ux:kCartCellPadding fy:UB_BOTTOM uy:-kCartGoodsNumBtnHeight],
                                                                   [self.ubo fw:UB_WIDTH uw:-(kCartGoodsNumBtnWidth + kCartCellMargin +kCartCellPadding + kCartGoodsPictureHeight) uh:kCartGoodsNumBtnHeight])];
    self.goodsPriceLabel.textAlignment = NSTextAlignmentLeft;
    self.goodsPriceLabel.backgroundColor = HZ_CLEAR_COLOR;
    self.goodsPriceLabel.text = [NSString stringWithFormat:@"￥%@",model.sale_price];
    self.goodsPriceLabel.textColor = HZ_ORANGE_COLOR;
    [self addSubview:self.goodsPriceLabel];
    
}

@end




